#pragma once
#include "Card.h"
#include "Types.h"

#include <iostream>
#include <string>
#include <cassert>

namespace RackNetPoker
{
	struct Player
	{
		enum PlayerState
		{
			PS_CHECK,
			PS_RAISE,
			PS_FOLD,
			PS_ALLIN,
			PS_NONE
		};

		std::string		m_name;
		PlayerState		m_state;
		Money			m_bid;
		Card			m_cards[2];
		Money			m_money;

		std::string ToString()
		{
			std::string tmp;
			std::stringstream ss;
			ss << m_money;

			tmp += m_name + "--> Card1: " + m_cards[0].ToString() + ", Card2: " + m_cards[1].ToString() + ", Money: " + ss.str();

			return tmp;
		}

		void Pay(Money money)
		{
			if(m_money >= money)
			{
				m_bid += money;
				m_money -= money;

				std::stringstream ss;
				ss << money;

				std::cout << m_name << "--> Pago: " << money << std::endl;
			}
			else //All-IN
			{
				m_bid += m_money;

				m_state = PS_ALLIN;

				std::stringstream ss;
				ss << money;

				std::cout << m_name << "-->Pago: " << m_money << std::endl;

				m_money = 0;
			}
		}

		void Turn(Money currentBid)
		{
			std::cout << m_name << "--> E' il tuo turno, fai la tua mossa [(0) = check, (1) = raise, (2) = fold]" << std::endl;

			int choose;
			std::cin >> choose;

			switch(choose)
			{
			case 0: 
				m_state = PS_CHECK;

				assert(currentBid >= m_bid);

				Pay(currentBid - m_bid);
				break;
			case 1:
				m_state = PS_RAISE;
				std::cout << "Di quanto rilanci?\n" << std::endl;

				int raiseValue;
				std::cin >> raiseValue;

				assert(m_bid + raiseValue > currentBid);

				Pay(raiseValue);
				break;
			case 2:
				m_state = PS_FOLD;
				break;
			}
		}
	};
}